package cn.huanzi.qch.baseadmin.travel.thotel.controller;

import cn.huanzi.qch.baseadmin.common.controller.*;
import cn.huanzi.qch.baseadmin.common.pojo.Result;
import cn.huanzi.qch.baseadmin.travel.thotel.pojo.THotel;
import cn.huanzi.qch.baseadmin.travel.thotel.service.THotelPlService;
import cn.huanzi.qch.baseadmin.travel.thotel.vo.THotelVo;
import cn.huanzi.qch.baseadmin.travel.thotel.service.THotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 酒店管理
 */
@Slf4j
@RestController
@RequestMapping("/hotel/")
public class THotelController extends CommonController<THotelVo, THotel, Integer> {

    @Autowired
    private THotelService tHotelService;

    @Autowired
    private THotelPlService tHotelPlService;

    @GetMapping("/")
    public ModelAndView toHotel() {
        return new ModelAndView("travel/hotel/hotel");
    }

    @GetMapping("/add")
    public ModelAndView toHotelAdd() {
        return new ModelAndView("travel/hotel/add");
    }

    @GetMapping("/edit")
    public ModelAndView toEdit(@RequestParam("hotelId") Integer hotelId, ModelAndView modelAndView) {
        Result<THotelVo> result = tHotelService.get(hotelId);
        THotelVo hotelVo = result.getData();
        modelAndView.addObject("hotel", hotelVo);
        modelAndView.setViewName("travel/hotel/edit");

        return modelAndView;
    }

    @GetMapping("/findpl")
    public Result findpl(@RequestParam("hotelId") Integer hotelId) {
        return Result.of(tHotelPlService.findPlByhotelId(hotelId));
    }


    /**
     * 查询所有酒店
     * @return 所有酒店信息
     */
    @GetMapping("/findAll")
    public ModelAndView findAll(ModelAndView modelAndView) {
        List<THotelVo> hotelList = tHotelService.findAll();
        modelAndView.addObject("hotels", hotelList);
        modelAndView.setViewName("travel/front-end/hotelReservation");

        return modelAndView;
    }



}
